package com.ctshk.sapp.order.hotel.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.hotel.dto.HotelOrderDetailDTO;
import com.ctshk.rpc.hotel.dto.HotelOrderIntegralExchangeDTO;
import com.ctshk.rpc.hotel.dto.HotelOrderPageDTO;
import com.ctshk.rpc.hotel.dto.HotelOrderPayQueryInfoDTO;
import com.ctshk.rpc.hotel.req.*;
import com.ctshk.rpc.hotel.service.IHotelOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 酒店订单表 前端控制器
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-08
 */
@Api(value = "酒店订单",tags = "酒店订单")
@RestController
@RequestMapping("/hotel/order")
public class HotelOrderController extends BaseController {
    @DubboReference
    IHotelOrderService hotelOrderService;
//    @ApiOperation(value="填写订单信息", notes="填写订单信息")
//    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "填写订单信息", operDesc = "填写订单信息")
//    @PostMapping("/save")
//    public Result saveHotelOrder(@RequestBody @Valid HotelPlaceOrderReq hotelPlaceOrderReq) {
//        TokenUser user = getCurrentUser(getRequest());
//        return hotelOrderService.addHotelOrder(hotelPlaceOrderReq,user);
//    }
    @ApiOperation(value = "酒店产品-订单中心-提交订单", notes = "酒店产品-订单中心-提交订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "酒店产品-订单中心-提交订单", operDesc = "酒店产品-订单中心-提交订单")
    @PostMapping("/submit")
    public Result<Long> submit(@Valid @RequestBody HotelOrderSaveReq hotelOrderSaveReq) {
        TokenUser currentUser = getCurrentUser(getRequest());
        return hotelOrderService.submit(hotelOrderSaveReq, currentUser);
    }

    @ApiOperation(value = "酒店订单-填写订单页-积分汇率换港币", notes = "酒店订单-填写订单页-积分汇率换港币")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "预订中心景点门票-填写订单页-积分汇率换港币", operDesc = "预订中心景点门票-填写订单页-积分汇率换港币")
    @GetMapping(value = "/conversionIntegral/{integral}")
    public Result<HotelOrderIntegralExchangeDTO> conversionIntegral(@PathVariable Long integral){
        return hotelOrderService.conversionIntegral(integral);
    }

    @ApiOperation(value = "预订中心酒店-支付页面-查询订单金额与时间", notes = "预订中心酒店-支付页面-查询订单金额与时间")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "预订中心巴士票-支付页面-查询订单金额与时间", operDesc = "预订中心巴士票-支付页面-查询订单金额与时间")
    @GetMapping(value = "/queryOrderInfo/{orderId}")
    public Result<HotelOrderPayQueryInfoDTO> queryOrderInfo(@PathVariable Long orderId){
        return hotelOrderService.queryOrderInfo(orderId);
    }

    @ApiOperation(value = "预订中心酒店-订单中心-支付订单", notes = "机场快线-订单中心-支付订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "机场快线-订单中心-支付订单", operDesc = "机场快线-订单中心-支付订单")
    @PostMapping("/pay/{orderId}")
    public Result<Long> pay(@PathVariable("orderId") Long orderId, @Valid @RequestBody List<HotelOrderCollectionReq> airportExpressOrderCollectionReqList) {
        TokenUser currentUser = getCurrentUser(getRequest());
        return hotelOrderService.pay(orderId, airportExpressOrderCollectionReqList, currentUser);
    }

//    @ApiOperation(value = "预订中心酒店-支付页面-下单", notes = "预订中心酒店-支付页面-下单")
//    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "预订中心巴士票-支付页面-下单", operDesc = "预订中心巴士票-支付页面-下单")
//    @PostMapping(value = "/add/order")
//    public Result payOrder(@RequestBody List<HotelPayOrderCollectionReq> reqList){
//        return hotelOrderService.payOrder(reqList,getCurrentUser(getRequest()).getId());
//    }

    @ApiOperation(value="订单中心-酒店订单分页查询列表", notes="订单中心-酒店订单分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "订单中心-巴士票订单分页查询列表", operDesc = "订单中心-巴士票订单分页查询列表")
    @PostMapping("/list")
    public Result<PageResponse<HotelOrderPageDTO>> queryBusLineList(@RequestBody HotelOrderPageReq hotelOrderPageReq) {
        PageResponse<HotelOrderPageDTO> response = hotelOrderService.queyList(hotelOrderPageReq);
        return Result.success(response);
    }

    @ApiOperation(value = "订单中心-查询酒店订单详情", notes = "订单中心-查询酒店订单详情")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "订单中心-查询巴士订单详情", operDesc = "订单中心-查询巴士订单详情")
    @GetMapping(value = "/queryOrderDetailInfo/{orderId}")
    public Result<HotelOrderDetailDTO> queryOrderDetailInfo(@PathVariable Long orderId){
        return hotelOrderService.queryOrderDetailInfo(orderId);
    }

    @ApiOperation(value = "订单中心酒店--修改旅客信息", notes = "订单中心酒店-修改旅客信息")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "订单中心巴士票--修改旅客信息", operDesc = "订单中心巴士票--修改旅客信息")
    @PostMapping(value = "/updateTourist")
    public Result updateTourist(@RequestBody HotelOrderTouristReq touristReq){
        return hotelOrderService.updateHotelOrderTourist(touristReq,getCurrentUser(getRequest()).getId());
    }

    @ApiOperation(value = "订单中心酒店--取消订单", notes = "订单中心酒店-取消订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "订单中心巴士票--取消订单", operDesc = "订单中心巴士票--取消订单")
    @PostMapping(value = "/cancel/order")
    public Result cancelOrder(@RequestBody HotelCancelOrderReq cancelOrderReq){
        return hotelOrderService.cancelOrder(cancelOrderReq,getCurrentUser(getRequest()).getId());
    }
}
